package com.isdepci.project.gasEmission.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.isdepci.framework.aspectj.lang.annotation.Log;
import com.isdepci.framework.aspectj.lang.enums.BusinessType;
import com.isdepci.project.gasEmission.domain.PurchasedEnergy;
import com.isdepci.project.gasEmission.service.IPurchasedEnergyService;
import com.isdepci.framework.web.controller.BaseController;
import com.isdepci.framework.web.domain.AjaxResult;
import com.isdepci.common.utils.poi.ExcelUtil;
import com.isdepci.framework.web.page.TableDataInfo;

/**
 * 能源购买Controller
 *
 * @author isdepci
 * @date 2023-09-01
 */
@RestController
@RequestMapping("/purchasedEnergy/purchasedEnergy")
public class PurchasedEnergyController extends BaseController
{
    @Autowired
    private IPurchasedEnergyService purchasedEnergyService;

    /**
     * 查询能源购买列表
     */
    @PreAuthorize("@ss.hasPermi('purchasedEnergy:purchasedEnergy:list')")
    @GetMapping("/list")
    public TableDataInfo list(PurchasedEnergy purchasedEnergy)
    {
        startPage();
        List<PurchasedEnergy> list = purchasedEnergyService.selectPurchasedEnergyList(purchasedEnergy);
        return getDataTable(list);
    }

    /**
     * 导出能源购买列表
     */
    @PreAuthorize("@ss.hasPermi('purchasedEnergy:purchasedEnergy:export')")
    @Log(title = "能源购买", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PurchasedEnergy purchasedEnergy)
    {
        List<PurchasedEnergy> list = purchasedEnergyService.selectPurchasedEnergyList(purchasedEnergy);
        ExcelUtil<PurchasedEnergy> util = new ExcelUtil<PurchasedEnergy>(PurchasedEnergy.class);
        return util.exportExcel(list, "purchasedEnergy");
    }

    /**
     * 获取能源购买详细信息
     */
    @PreAuthorize("@ss.hasPermi('purchasedEnergy:purchasedEnergy:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(purchasedEnergyService.selectPurchasedEnergyById(id));
    }

    /**
     * 新增能源购买
     */
    @PreAuthorize("@ss.hasPermi('purchasedEnergy:purchasedEnergy:add')")
    @Log(title = "能源购买", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PurchasedEnergy purchasedEnergy)
    {
        return toAjax(purchasedEnergyService.insertPurchasedEnergy(purchasedEnergy));
    }

    /**
     * 修改能源购买
     */
    @PreAuthorize("@ss.hasPermi('purchasedEnergy:purchasedEnergy:edit')")
    @Log(title = "能源购买", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PurchasedEnergy purchasedEnergy)
    {
        return toAjax(purchasedEnergyService.updatePurchasedEnergy(purchasedEnergy));
    }

    /**
     * 删除能源购买
     */
    @PreAuthorize("@ss.hasPermi('purchasedEnergy:purchasedEnergy:remove')")
    @Log(title = "能源购买", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(purchasedEnergyService.deletePurchasedEnergyByIds(ids));
    }
}
